package com.shop.seckill.controller;

import com.base.common.entity.User;
import com.base.common.http.HttpResult;
import com.base.common.http.HttpStatus;
import com.base.common.utils.UserUtils;
import com.shop.seckill.service.SecKillOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "/pay")
public class PayController {

    @Autowired
    private SecKillOrderService seckillOrderService;

    /***
     * 创建二维码
     * @return
     */
    @RequestMapping(value = "/create/native")
    public HttpResult createNative(HttpServletRequest request){
        //根据用户名字，查询用户的秒杀订单信息
        User user = UserUtils.getUser(request);
        if(user == null) {
            return HttpResult.error(HttpStatus.SC_FORBIDDEN,"请先登录!");
        }

        //根据订单信息创建二维码
        HttpResult result = seckillOrderService.createNativeQrcode(user.getId());

        return result;
    }
}
